/*
 * Jenny Ruppen 09-730-391
 * Sebastien Goldberg 08-914-855
 * Henry Raymond 08-928-061
 * Stefan Mussato 09-752-270
 */
 
package ch.uzh.ifi.sopra.gruppe9.game;


import com.jme3.scene.Node;


/**
 * Draws a buying agent to the screen in 2D or in 3D.
 */
public class GuiBuyingAgent implements IUpdatable {
	
	
	/**
	 * Corresponding buying agent card.
	 */
	private BuyingAgent card;
	
	
	/**
	 * Offset of the 2D coordinate system of this buying agent.
	 */
	private GUI.Offset offset;
	
	
	/**
	 * 2D position of the buying agent in the x axis. (Assuming the window has a width of 1024 pixel.)
	 */
	private int positionX;
	
	
	/**
	 * 2D position of the buying agent in the y axis. (Assuming the window has a height of 768 pixel.)
	 */
	private int positionY;
	
	
	/**
	 * Z-Index of the element. An element with a higher index will cover an element with a lower one.
	 */
	private int zIndex;
	
	
	/**
	 * Timer for animation. 
	 */
	private float timer = 0.0f;
	
	
	/**
	 * Geometry node of the 2D buying agent.
	 */
	private Node buyingAgent2D;
	
	
	/**
	 * Marks the buying agent as used. (The buying agent can therefore not be used for actions.)
	 */
	private boolean used = false;
	
	
	/**
	 * Constructor: Loads card of the buying agent
	 */
	public GuiBuyingAgent(int id) {
		card = new BuyingAgent(id);
	}
	
	
	/**
	 * Position and return 2D image of the buying agent.
	 */
	public Node get2D(GUI.Offset offset, int positionX, int positionY, int zIndex) {
		this.offset = offset;
		this.positionX = positionX;
		this.positionY = positionY;
		this.zIndex = zIndex;
		
		buyingAgent2D = getColor2D(card.getColor(), offset, positionX, positionY, zIndex);
		
		return buyingAgent2D;
	}
	
	
	/**
	 * Position and return 2D image of a generic buying agent with a given color.
	 * If BuyingAgent.Color.NONE is used as color, "two buying agents" is returned.
	 */
	public static Node getColor2D(BuyingAgent.Color color, GUI.Offset offset, int positionX, int positionY, int zIndex) {

		
		GuiQuad agent = new GuiQuad();
		agent.setAbsolutePositionSize(0, 0, 40, 75, 0);
		
		if(color == BuyingAgent.Color.BLUE) {
			agent.setMaterial(MaterialManager.getBlueBuyingAgent(), 0.0f, 0.0f, 1.0f, 1.0f);
		} else if(color == BuyingAgent.Color.GREEN) {
			agent.setMaterial(MaterialManager.getGreenBuyingAgent(), 0.0f, 0.0f, 1.0f, 1.0f);
		} else if(color == BuyingAgent.Color.YELLOW) {
			agent.setMaterial(MaterialManager.getYellowBuyingAgent(), 0.0f, 0.0f, 1.0f, 1.0f);
		} else if(color == BuyingAgent.Color.PURPLE) {
			agent.setMaterial(MaterialManager.getPurpleBuyingAgent(), 0.0f, 0.0f, 1.0f, 1.0f);
		} else if(color == BuyingAgent.Color.ORANGE) {
			agent.setMaterial(MaterialManager.getOrangeBuyingAgent(), 0.0f, 0.0f, 1.0f, 1.0f);
		} else if(color == BuyingAgent.Color.NONE) {
			agent.setMaterial(MaterialManager.getTwoBuyingAgents(), 0.0f, 0.0f, 1.0f, 1.0f);
		}
		agent.create();
		agent.setLocalTranslation(GUI.calculateX(offset, positionX), GUI.calculateY(offset, positionY), (float)zIndex);
		return agent;
	}
	
	
	/**
	 * Returns ID of the buying agent card.
	 */
	public int getId() {
		return card.getId();
	}
	
	
	/**
	 * Returns color of the buying agent card.
	 */
	public BuyingAgent.Color getColor() {
		return card.getColor();
	}


	@Override
	public void update(float delta) {
		timer += delta;
	}


	/**
	 * Checks if the buying agent has been used.
	 */
	public boolean isUsed() {
		return used;
	}


	public void setUsed(boolean used) {
		this.used = used;
	}


	public GUI.Offset getOffset() {
		return offset;
	}


	public int getPositionX() {
		return positionX;
	}


	public int getPositionY() {
		return positionY;
	}


	public int getzIndex() {
		return zIndex;
	}
	

}
